let keyword = document.querySelector('[name="keyword"]').value
function queryBs(){
  axios({
    method: 'get',
    url:`http://localhost:3000/bookList?keyword=${keyword}`
  }).then(res => {
    let data = res.data
    document.querySelector('tbody').innerHTML = data.map(item =>
      `<tr id=book${item.id}>
  <td>${item.id}</td>
  <td>${item.BookName}</td>
  <td>${item.author}</td>
  <td>
    <input type="button" value="修改" onclick='Update(${item.id})'>
    <input type="button" value="删除" onclick='Delete(${item.id})'>
  </td>
</tr>`
    ).join('')
  })
}
window.addEventListener("load", () => {
  queryBs()

})
function Delete(id) {
  if (confirm(`是否要删除 id 为${id}的图书数据？`)) {
    axios({
      method: 'delete',
      url: `http://localhost:3000/bookList/${id}`
    }).then(res => {
      document.querySelector(`#book${id}`).remove()

    })
  }


}
function add() {
  location.href = './addorupdate.html'

}
function Update(id) {
  location.href = `./addorupdate.html?id=${id}`

}

function Search(){
//   let keyword = document.querySelector('[name="keyword"]').value
//   axios({
//     method: 'get',
//     url: `http://localhost:3000/bookList?keyword=${keyword}`
//   }).then(res => {
//     let data = res.data
//     document.querySelector('tbody').innerHTML = data.map(item =>
//       `<tr id=book${item.id}>
//   <td>${item.id}</td>
//   <td>${item.BookName}</td>
//   <td>${item.author}</td>
//   <td>
//     <input type="button" value="修改" onclick='Update(${item.id})'>
//     <input type="button" value="删除" onclick='Delete(${item.id})'>
//   </td>
// </tr>`
//     ).join('')
//   })
queryBs()
}